/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package testgui;

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

/**
 *
 * @author Administrator
 */
public class Enemy extends Player{
    
    
    private int xPosEnemy = 0;
    private int yPosEnemy = 0;
    private int[] intArraySizeOfHexGridEnemy = new int[2];
    private int[][] intArrayHexGridEnemy = new int[intArraySizeOfHexGridEnemy[0]]
                                             [intArraySizeOfHexGridEnemy[1]];
    private int[] currentPositionEnemy = new int[2];
    private JLabel jLabelConntectedToPlayerEnemy;


    
    
public Enemy(int[] intArrayStartingPos, int numberOfRows, 
            int numberOfColumns, int startPosHoz, int startPosVert, JLabel jLabel)
    {

        xPosEnemy = intArrayStartingPos[0];
        yPosEnemy = intArrayStartingPos[1];
        
        intArraySizeOfHexGridEnemy[0] = numberOfRows;
        intArraySizeOfHexGridEnemy[1] = numberOfColumns;
        
        currentPositionEnemy[0] = startPosHoz;
        currentPositionEnemy[1] = startPosVert;
        
        jLabelConntectedToPlayerEnemy = jLabel;
        
        //System.out.println(currentPositionEnemy[0]);
        //System.out.println(jLabelConntectedToPlayerEnemy);
    }



    private boolean isCurrentRowEven()
    {
        return currentPositionEnemy[0] % 2 == 0;
    }
    
    private boolean isCurrentColumnEven()
    {
        return currentPositionEnemy[1] % 2 == 0;
    }
    
    private void playerUpdatePosNorthWest()
    {
        updatePlayerPos(getXPos() - 16, getYPos() - 27);
        
        if(isCurrentRowEven() && isCurrentColumnEven())
        {
            //System.out.println("even, even");
            updatePlayerPosInGrid(-1, -1);
        }
        
        else if(!isCurrentRowEven() && isCurrentColumnEven())
        {
        //System.out.println("odd, even");
        updatePlayerPosInGrid(-1, -1);
        }
        
        else if(isCurrentRowEven() && !isCurrentColumnEven())
        {
        //System.out.println("even, odd");
        updatePlayerPosInGrid(0, -1);
        }
        
        else
        {
        //System.out.println("odd, odd");
        updatePlayerPosInGrid(0, -1);
        }
        
       
    }
    
    private void playerUpdatePosNorth()
    {

    }
    
    private void playerUpdatePosNorthEast()
    {
       updatePlayerPos(getXPos() + 16, getYPos() - 27);
       
        if(isCurrentRowEven() && isCurrentColumnEven())
        {
            //System.out.println("even, even");
            updatePlayerPosInGrid(0, -1);
        }
        
        else if(!isCurrentRowEven() && isCurrentColumnEven())
        {
        //System.out.println("odd, even");
        updatePlayerPosInGrid(0, -1);
        }
        
        else if(isCurrentRowEven() && !isCurrentColumnEven())
        {
        //System.out.println("even, odd");
        updatePlayerPosInGrid(+1, -1);
        }
        
        else
        {
        //System.out.println("odd, odd");
        updatePlayerPosInGrid(+1, -1);
        }
        

    }
    
    private void playerUpdatePosWest()
    {
       updatePlayerPos(getXPos() - 32, getYPos());
       updatePlayerPosInGrid(-1, 0);
    }
    
    private void playerUpdatePosEast()
    {
       updatePlayerPos(getXPos() + 32, getYPos());
       updatePlayerPosInGrid(+1, 0);
    }
    
    private void playerUpdatePosSouthWest()
    {
       updatePlayerPos(getXPos() - 16, getYPos() + 27);
       
       if(isCurrentRowEven() && isCurrentColumnEven())
        {
            //System.out.println("even, even");
            updatePlayerPosInGrid(-1, +1);
        }
        
        else if(!isCurrentRowEven() && isCurrentColumnEven())
        {
        //System.out.println("odd, even");
        updatePlayerPosInGrid(-1, +1);
        }
        
        else if(isCurrentRowEven() && !isCurrentColumnEven())
        {
        //System.out.println("even, odd");
        updatePlayerPosInGrid(0, +1);
        }
        
        else
        {
        //System.out.println("odd, odd");
        updatePlayerPosInGrid(0, +1);
        }
    }
    
    private void playerUpdatePosSouth()
    {

    }
    
    private void playerUpdatePosSouthEast()
    {
       updatePlayerPos(getXPos() + 16, getYPos() + 27);
       
       if(isCurrentRowEven() && isCurrentColumnEven())
        {
            //System.out.println("even, even");
            updatePlayerPosInGrid(0, +1);
        }
        
        else if(!isCurrentRowEven() && isCurrentColumnEven())
        {
        //System.out.println("odd, even");
        updatePlayerPosInGrid(0, +1);
        }
        
        else if(isCurrentRowEven() && !isCurrentColumnEven())
        {
        //System.out.println("even, odd");
        updatePlayerPosInGrid(+1, +1);
        }
        
        else
        {
        //System.out.println("odd, odd");
        updatePlayerPosInGrid(+1, +1);
        }
        
    }

    public int getXPos()
    {
        return xPosEnemy;
    }
    
    public int getYPos()
    {
        return yPosEnemy;
    }

    private void updatePlayerPosInGrid(int x, int y)
    {
        System.out.println("X: " + x + ", Y: " + y);
        currentPositionEnemy[0] += x;
        currentPositionEnemy[1] += y;
    }
    
    private void updatePlayerPos(int x, int y)
    {
        xPosEnemy = x;
        yPosEnemy = y;
    }
    
    public int[] getCurrentPosInArray()
    {
        return currentPositionEnemy;
    }
    
    public int getCurrentXPosInGrid()
    {
        return currentPositionEnemy[0];
    }
    
    public int getCurrentYPosInGrid()
    {
        return currentPositionEnemy[1];
    }

    public JLabel getJLabel()
    {
        return jLabelConntectedToPlayerEnemy;
    }
    
    public void persuePlayer(Player player, SimpleGUI sGUI)
    {
        moveTowardsPosition(player.getCurrentPosInArray(), sGUI);
    }

    public void moveTowardsPosition(int[] positon, SimpleGUI sGUI)
    {
        int differenceX = currentPositionEnemy[0] - positon[0];
        int differenceY = currentPositionEnemy[1] - positon[1];
        
        
        
        //NorthWest
        if(differenceX > 0 && differenceY > 0)
        {
            System.out.println("North West Triggered");
            movePlayerNorthWest(sGUI);
        }
        
        //NorthEast
        else if(differenceX < 1 && differenceY > 0)
        {
            movePlayerNorthEast(sGUI);
        }
        
        else if(differenceX > 0 && differenceY == 0)
        {
            movePlayerWest(sGUI);
        }
        
        else if(differenceX < 0 && differenceY == 0)
        {
            movePlayerEast(sGUI);
        }
        
        else if(differenceX > 0 && differenceY < 1)
        {
            movePlayerSouthWest(sGUI);
        }
        
        else
        {
            System.out.println("South East Triggered by: " 
                    + getCurrentXPosInGrid() +", " + getCurrentYPosInGrid() );
            movePlayerSouthEast(sGUI);
        }
        
        System.out.println("current pos: " +  getCurrentXPosInGrid() +", " +
                getCurrentYPosInGrid() + " diffX: " + differenceX 
                + " diffY: " + differenceY);
    }
    
    public void movePlayerNorthWest(SimpleGUI sGUI)
    {
        if(sGUI.getEngineUsed().requestPlayerMoveNorthWest(this, sGUI))
        {
            playerUpdatePosNorthWest();
        }
    }
    public void movePlayerNorth(SimpleGUI sGUI)
    {
   
    }
    
    public void movePlayerNorthEast(SimpleGUI sGUI)
    {
        if(sGUI.getEngineUsed().requestPlayerMoveNorthEast(this, sGUI))
        {
            playerUpdatePosNorthEast();
        }
    }
    public void movePlayerWest(SimpleGUI sGUI)
    {
        if(sGUI.getEngineUsed().requestPlayerMoveWest(this, sGUI))
        {
            playerUpdatePosWest();
        }
    }
    public void movePlayerEast(SimpleGUI sGUI)
    {
        if(sGUI.getEngineUsed().requestPlayerMoveEast(this, sGUI))
        {
            playerUpdatePosEast();
        }
    }
    
    public void movePlayerSouthWest(SimpleGUI sGUI)
    {
        if(sGUI.getEngineUsed().requestPlayerMoveSouthWest(this, sGUI))
        {
            playerUpdatePosSouthWest();
        }
    }
    
    public void movePlayerSouth(SimpleGUI sGUI)
    {
        
    }
    
    public void movePlayerSouthEast(SimpleGUI sGUI)
    {

        if(sGUI.getEngineUsed().requestPlayerMoveSouthEast(this, sGUI))
        {
            playerUpdatePosSouthEast();
        }
    }
}
